import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.*;

public class Terminal extends JPanel{
        JTextArea taEdit;
        static  JTextArea ta;
        static String adres =null;
        private final static String newline = "\n";
        static  JScrollPane jsp;
        int licznik=0;
        JButton bold = new JButton(new ImageIcon("icon/format-text-bold.png"));
        JButton italic = new JButton(new ImageIcon("icon/format-text-italic.png"));
        JButton striket = new JButton(new ImageIcon("icon/format-text-striket.png"));
        String text;
        
        public Terminal(String adres){
        	this.adres=adres;
        	System.out.println(adres);


            /**
            GroupLayout layout = new GroupLayout();
            setLayout(layout);
            layout.setAutoCreateGaps(true);
            layout.setAutoCreateContainerGaps(true);
             */
             ta = new JTextArea();
             ta.setEditable(false);
             ta.setText(" - - WERJSA TESTOWA - - ");
             ta.append("\n");
             ta.setLineWrap(true);


             jsp = new JScrollPane(ta);
             jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
             jsp.setPreferredSize(new Dimension(410, 250));
             jsp.setMinimumSize(new Dimension(10, 10));
             jsp.setAutoscrolls(true);

             add(jsp);

        JPanel srodek = new JPanel();

        srodek.add(bold);
        srodek.add(italic);
        srodek.add(striket);
        
        add(srodek);

        taEdit = new JTextArea();
        JScrollPane jspEdit = new JScrollPane(taEdit);
        jspEdit.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        jspEdit.setPreferredSize(new Dimension(410, 65));
        jsp.setMinimumSize(new Dimension(10, 10));

        add(jspEdit);

        taEdit.addKeyListener(new KeyAdapter() {
                public void keyPressed(KeyEvent ke) {
                        int thisKey = ke.getKeyCode();

                        if (thisKey == KeyEvent.VK_ENTER) {
                        text = taEdit.getText();
                        ta.append("cinior :"+text + newline);
                        taEdit.setText(" ");
                        ke.consume();

                        try {
                     		Socket s = new Socket(Terminal.adres, 8177);
                     		PrintWriter out = new PrintWriter(s.getOutputStream());
                     		//Wyslanie adresu IP
                     		out.println(text);
                     		out.flush();
                     		}
                     		catch(IOException e)
                     		{}


                        }
                }
        });
                        bold.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e){
                        Font fbold = new Font("Impact", Font.BOLD, 14);                     
                        taEdit.setFont(fbold);
                        
                        }
                        });

 }}

